package net.htjs.juc.chapter06.accountsafe;

public class AccountSafe implements Account{

    private Integer balance;

    public AccountSafe(Integer balance) {
        this.balance = balance;
    }

    @Override
    public Integer getBalance() {
        synchronized (this) {
            return this.balance;
        }
    }

    @Override
    public void withdraw(Integer amount) {
        synchronized (this) {
            this.balance -= amount;
        }
    }

    public static void main(String[] args) {
        AccountSafe account = new AccountSafe(10000);
        Account.demo( account);
    }
}
